#include "I_BaseLib.h"

ScreenObject::ScreenObject (const wchar_t* bitmap_name)
{
	
	bitmap = new cBITMAP();
	bitmap->Load(bitmap_name);
	x = 0;
	y = 0;
	width = bitmap->pHeader->Width;
	height = bitmap->pHeader->Height;
	selected = false;
	SetColor(COLOR(255,255,255));

}

ScreenObject::~ScreenObject(void)
{
	Connections.~vector();
	delete bitmap;
}

int ScreenObject::HitBox(int posx, int posy)
{
	if ( (posx >= x) && (posy >= y) && (posx <= x+width) && (posy <= y+height )) return true;
	else return false;

}

void ScreenObject::Render (BASE_RENDERER* pRenderer)
{
	//blue, green, red
	COLOR col;
	if (selected) col = COLOR(0,0,255);
	else col = COLOR(255,255,255);
	if (bitmap)
		bitmap->Render(x,y,pRenderer);
	else
		pRenderer->DrawRectangle(x,y,x+width,y+height,col,1);
}

void ScreenObject::RenderConnections(BASE_RENDERER* pRenderer, COLOR col)
{
	for (std::vector<ScreenObject*>::size_type i=0;i<Connections.size();i++)
	{
		pRenderer->DrawLine(col,(int) x + width,(int) y + height,Connections[i]->GetPosX(),Connections[i]->GetPosY(),1);
	}
}
